package com.situ.mall.admin.config;

import com.situ.mall.admin.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//配置类
//介入springmvc的配置
@Configuration

public class MyWebMVCConfig implements WebMvcConfigurer {

    @Value("${file.path}")
    private String filepath;
    @Value("${file.location}")
    private String fileLocation;

    //添加拦截器

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())//创建一个拦截器对象
                .addPathPatterns("/**")//设置放行的文件
                .excludePathPatterns(filepath+"**","/login","/css/**","/js/**","/lib/**","/images/**");//设置拦截的对象
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(filepath+"**")//放图片的请求地址
                .addResourceLocations("file:" +fileLocation);//放图片的文件夹
    }
}
